<include file="Public:header" />
<include file="Public:leftside" />
<div class="main-content">
	<div class="breadcrumbs breadcrumbs-fixed" id="breadcrumbs">
		<ul class="breadcrumb">
			<li> <i class="icon-home home-icon"></i>
				<a href="/">首页</a>
			</li>
			<li class="active">分类管理</li>
		</ul>
	</div>
	<section class="scrollable wrapper">
		<!-- 操作提示  start -->
		<!-- 操作提示  end -->

		<header class="header clearfix">
			<div class="row m-t-sm">
				<a href="{:U('portal/trem_list_add')}" class="btn btn-sm btn-primary"><i class="fa fa-plus"></i> 添加分类</a>
			</div>
		</header>
		<section class="panel panel-default">
			<table class="table table-striped b-t b-light text-sm">
				<thead>
					<tr>
						<th width="20"></th>
						<th width="80">排序</th>
						<th>分类名称</th>
						<th class="center" width="100">操作</th>
					</tr>
				</thead>
				<tbody>
					<foreach name="list" item="v">
					<tr class="pid_0">
						<td>
							<notempty name="v['child']">
								<a href="javascript:;" onclick="tab_switch({$v.term_id})" class="tab_jia_{$v.term_id}" style="display: block;"> <i class="fa fa-plus"></i></a>
								<a href="javascript:;" onclick="tab_switch({$v.term_id})" class="tab_jian_{$v.term_id}" style="display: none;"><i class="fa fa-minus"></i></a>
							</notempty>
						</td>
						<td><input type="text" class="form-control" fieldid="{$v.term_id}" fieldname="sort" value="{$v.listorder}" size="{$v.listorder}"></td>
						<td>
							<div class="col-md-12">{$v.name} </div>
						</td>
						<td class="center">
							<a href="{:U('portal/trem_list_edit',array('id'=>$v['term_id']))}">修改</a>&nbsp;
							<a href="javascript:void(0);" onclick="deleteArticleClass({$v.term_id})">删除</a>
						</td>
					</tr>
						<foreach name="v['child']" item="vo">
							<tr class="pid_{$v.term_id}" style="display: none;">
								<td></td>
								<td><input type="text" class="form-control" fieldid="{$vo.term_id}" fieldname="sort" value="{$vo.listorder}" size="{$vo.listorder}"></td>
								<td>
									<div class="col-md-1"></div>
									<div class="col-md-11">
										{$vo.name} </div>
								</td>
								<td class="center">
									<a href="{:U('portal/trem_list_edit',array('id'=>$vo['term_id']))}">修改</a>
									<a href="javascript:void(0);" onclick="deleteArticleClass({$vo.term_id})">删除</a>
								</td>
							</tr>
						</foreach>
					</foreach>
					
				</tbody>
			</table>
		</section>
		<script type="text/javascript">
			function tab_switch(class_id) {
				if($(".pid_" + class_id).css('display') != 'none') {
					$(".tab_jian_" + class_id).hide();
					$(".tab_jia_" + class_id).show();
					$(".pid_" + class_id).hide(300);
				} else {
					$(".tab_jian_" + class_id).show();
					$(".tab_jia_" + class_id).hide();
					$(".pid_" + class_id).show(500);
				}
			}
			//删除分类
			function deleteArticleClass(class_id) {
				layer.confirm('是否确认删除？', {
					  btn: ['确认','不了'] //按钮
				}, function(){
					 	$.ajax({
								type: "post",
								url: "{:U('Portal/del_trem')}",
								async: true,
								data: {
									"class_id": class_id
								},
								success: function(data) {
									if(data["code"] == 0) {
										layer.msg('删除失败')
									} 
									if(data["code"] == 1) {
										layer.msg('删除成功')
										setTimeout("location.reload()",1000)
									} 
									if(data["code"] == 2) {
										layer.msg('请先删除子类！')
									} 
								}
							})
				}, function(){
					  
				});
				
			}
			$("table input").change(function() {
				var fieldid = $(this).attr('fieldid');
				var fieldvalue = $(this).val();
				$.ajax({
					type: "post",
					url: "{:U('Portal/modifyField')}",
					data: {
						'fieldid': fieldid,
						'sort': fieldvalue
					},
					async: true,
					success: function(data) {
						if(data['code'] ==1) {
							layer.msg('更新成功')
						}
					}
				});
			});
		</script>

	</section>

</div>

<include file="Public:footer" />